package com.czl.module_storehouse.activity.intostore.selectorder;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;

import com.czl.module_base.activity.BaseActivity;

import com.czl.module_storehouse.databinding.ActivityViewOrderItemBinding;
import com.czl.module_storehouse.R;
import com.czl.module_storehouse.adapter.ViewOrderItemAdapter;
import com.czl.module_storehouse.event.PurchaseProjectListBeanEvent;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.ArrayList;

/**
 * @author xubin
 */
public class ViewOrderItemActivity extends BaseActivity<ActivityViewOrderItemBinding> {
    private ViewOrderItemAdapter mAdapter;

    @Override
    protected ActivityViewOrderItemBinding getBinding(LayoutInflater layoutInflater) {
        return ActivityViewOrderItemBinding.inflate(layoutInflater);
    }

    @Override
    protected void initData(Bundle savedInstanceState) {
        mToolBinding.toolbarContentTitle.setText("入库物品");
        mAdapter = new ViewOrderItemAdapter(R.layout.item_view_order_item, new ArrayList<>());
        binding.recyclerView.setAdapter(mAdapter);
        binding.textBack.setOnClickListener(v -> finish());
        EventBus.getDefault().register(this);
    }

    @Subscribe(threadMode = ThreadMode.POSTING, sticky = true)
    public void onDataEvent(PurchaseProjectListBeanEvent event) {
        if (event == null) {
            return;
        }
        if (mAdapter != null) {
            mAdapter.addData(event.getList());
        }
    }
}
